package com.itheima.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        ServerSocket socket = new ServerSocket(10000);
        Socket accept = socket.accept();
        InputStream is = accept.getInputStream();
        int i;
        byte[] b = new byte[1024];
        while((i = is.read(b))!=-1){
            System.out.println(new String(b,0,i));
        }

        OutputStream os = accept.getOutputStream();
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        os.write(str.getBytes());

        is.close();
        os.close();
        socket.close();
    }
}
